#include<bits/stdc++.h>
using namespace std;

void an(){
    int a,b;
    cin>>a>>b;
    map<int,int,greater<int>> l;
    vector<int> h(a);
    for(int i=0;i<a;i++){
        
        cin>>h[i];
        map<int, int>::iterator it = l.find(h[i]);
        if(it!=l.end()){
            it->second++;
        }
        else{
            l.insert(make_pair(h[i],1));
        }

    }
    int t=l.size();
    //cout<<t<<endl;
    vector<int> keys(l.size());
    transform(l.begin(),l.end(),keys.begin(),[](const pair<const int,int>& pair){return pair.first;});
    sort(keys.begin(),keys.end(),[&](int key1, int key2) { return l[key1] < l[key2]; });
    for (int key : keys) {
        if(l[key]<=b){
            t--;
            b-=l[key];
        }
        else{
            break;
        }
        //std::cout << key << " => " << l[key] << std::endl;
    }
    if(t<=1){
        cout<<1<<endl;
    }
    else{
        cout<<t<<endl;
    }

}
int main(){
    int x;
    cin>>x;
    while(x--){
        an();
    }
    return 0;
}